package com.example.leetcode;


import java.util.List;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StreamUtils;

/**
 * @description: TODO
 * @author: Sarah
 * @modified By: Sarah
 * @date: Created in 2021/8/4 14:42
 * @version:v1.0
 */
public class lll {

    public static void main(String[] args) {
    }

    public boolean hasCycle(ListNode head) {
        ListNode p1 = head;
        ListNode p2 = head.next;
        if(p2==null||p1==null)
            return false;
        while(p1!=p2){
            if(p1.next==null || p2.next==null){
                return false;
            }

            if (p2.next.next == null) {
                return false;
            }
            p1=p1.next;
            p2=p2.next.next;
        }
        return  true;
    }
}

class ListNode {

    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
        next = null;
    }
}